package com.lagou.service;

import org.apache.dubbo.config.annotation.Reference;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

@Service
public class ConsumerService {

    private Logger logger = Logger.getLogger(this.getClass());

    // 1分钟，一个线程：一次调用100ms，60000/100 = 600次；2000/600 = 4
    private static ExecutorService executor = Executors.newFixedThreadPool(4);

    @Reference(check = false,loadbalance = "random")
    private HelloService helloService;

    public String sayHello(String name, int timeToWait) {
        return helloService.sayHello(name, timeToWait);
    }

    public void cal(){
        for (int i = 0; i < 1000; i++) {
            executor.submit(()-> helloService.methodA());
            executor.submit(()-> helloService.methodB());
            executor.submit(()-> helloService.methodC());
        }
    }

}
